﻿namespace NTrace
{
  using System;
  using ICSharpCode.NRefactory.PrettyPrinter;

  public class VBNetLanguage : TargetLanguage
  {
    public override IOutputAstVisitor CreatePrinter()
    {
      return new VBNetOutputVisitor();
    }

    public override OriginalSourceWrapper CreateSourceWrapper(String fileName, System.IO.TextWriter writer)
    {
      return new VBNetSourceWrapper(this, fileName, writer);
    }

    public override String StartSourceWrapper(String fileName, int line)
    {
      return String.Format("#ExternalSource(\"{0}\", {1})", fileName, line);
    }

    public override String StopSourceWrapper()
    {
      return "#End ExternalSource";
    }

    private class VBNetSourceWrapper : OriginalSourceWrapper
    {
      private VBNetLanguage owner;
      private System.IO.TextWriter writer;

      public VBNetSourceWrapper(VBNetLanguage owner, String fileName, System.IO.TextWriter writer)
        : base(fileName, writer)
      {
        this.owner = owner;
        this.writer = writer;
        this.writer.WriteLine(this.owner.StartSourceWrapper(fileName, 1));
      }

      public override void Dispose()
      {
        this.writer.WriteLine(owner.StopSourceWrapper());
      }
    }
  }
}
